﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Xml;
using JumbotCms.Common;

namespace JumbotCms.WebFile.Writer
{
    public partial class _apply_index : JumbotCms.API.UserCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User_Load("", "html");
            if (q("act") != "save")
            {
                Response.Write(GetPageHtml("writer_apply"));
            }
            else
            {
                if (!CheckFormUrl())
                    Response.End();
                doh.Reset();
                doh.ConditionExpress = "UserId=@userid and applytype=1 and checked=0";
                doh.AddConditionParameter("@userid", UserId);
                if (doh.Exist("jcms_normal_user_apply"))
                    Response.Write("JumbotCms.Alert('请勿多次申请', '0');");
                else
                {
                    string _txtLanguages = f("txtLanguages");
                    string _txtGraduateFrom = f("txtGraduateFrom");
                    string _txtStudyWay = f("txtStudyWay");
                    
                    string _txtMobileTel = f("txtMobileTel");
                    string _txtTelephone = f("txtTelephone");
                    string _txtCardUserName = f("txtCardUserName");
                    string _txtCardBank = f("txtCardBank");
                    string _txtCardNumber = f("txtCardNumber");
                    doh.Reset();
                    doh.ConditionExpress = "id=@id and state=1";
                    doh.AddConditionParameter("@id", UserId);
                    doh.AddFieldItem("Languages", _txtLanguages);
                    doh.AddFieldItem("GraduateFrom", _txtGraduateFrom);
                    doh.AddFieldItem("StudyWay", _txtStudyWay);
                    
                    doh.AddFieldItem("MobileTel", _txtMobileTel);
                    doh.AddFieldItem("Telephone", _txtTelephone);
                    doh.AddFieldItem("CardUserName", _txtCardUserName);
                    doh.AddFieldItem("CardBank", _txtCardBank);
                    doh.AddFieldItem("CardNumber", _txtCardNumber);
                    doh.Update("jcms_normal_user");
                    doh.Reset();
                    doh.AddFieldItem("UserId", UserId);
                    doh.AddFieldItem("ApplyInfo", "申请成为" + site.WriterItem);
                    doh.AddFieldItem("ApplyType", 1);
					doh.AddFieldItem("ApplyNumber", 0);
                    doh.AddFieldItem("ApplyTime", DateTime.Now.ToString());
                    doh.AddFieldItem("ApplyIP",GetUserIp());
                    doh.AddFieldItem("Checked", 0);
                    doh.Insert("jcms_normal_user_apply");
                    string _mailBody = "ID：[" + UserId + "]，用户名[" + UserName + "]的会员于" + DateTime.Now.ToString() + "申请成为" + site.WriterItem;
                    if (SendServiceNotice(site.Name + "会员申请成为" + site.WriterItem, _mailBody, Str2Str(f("ddlNoticeMode"))))
                        Response.Write("JumbotCms.Alert('申请成功,等待审核', '1', \"window.location='../index/index.aspx';\");");
                    else
                        Response.Write("JumbotCms.Alert('申请成功,等待审核', '1', \"window.location='../index/index.aspx';\");");
                }
            }
        }
    }
}
